package com.huike.springboot1.demos.controller;

import com.huike.springboot1.demos.Mapper.RoleMapper;
import com.huike.springboot1.demos.Mapper.User1Mapper;
import com.huike.springboot1.demos.Mapper.UserMapper;
import com.huike.springboot1.demos.pojo.User;
import com.huike.springboot1.demos.pojo.User1;
import com.huike.springboot1.demos.pojo.Role;
import com.huike.springboot1.demos.service.User1Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;
import java.util.Calendar;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

//控制层
@Controller
public class LoginController {
    @Autowired
    UserMapper userMapper;
    @GetMapping("/toLogin")
    public String toLogin(Model model) {
//        添加属性，返回currentYear属性数值
        model.addAttribute("currentYear", Calendar.getInstance().get(Calendar.YEAR));
        return "login";//返回到的页面
    }

//    // Spring-MVC 的映射注解属性：
////     produces = "text/html;charset=utf-8"：浏览器收到后会把返回字符串按 HTML 解析，而不是纯文本
//    @PostMapping(value = "/login", produces = "text/html;charset=utf-8")
//    @ResponseBody
////    如果两端参数名称不同则用@RequestParam注解括起
////    因为创建了User对象所以能直接使用(UserMapper userMapper,可省略创建对象过程)，
////          在前端form表单中收集input的name属性值和User类中的成员变量相同
//    public String login(User user, HttpSession session) {
////        System.out.println(user);
//        User user1 = userMapper.signSelect(user);
//        if (user1 == null) {
//            return "账号或密码错误，<a href='/toLogin'>返回上一页</a>";
//        } else {
//            session.setAttribute("loginUser", user);
//            return "登录成功！<a href='/productList1'>进入首页</a>";
//        }
//    }

//    @Autowired
//    User1Mapper user1Mapper;
//    @GetMapping("/roles")
//    public String toAdmin(Model model) {
//        model.addAttribute("users", user1Mapper.user1Select());
//        return "admin/admin";//返回到的页面
//    }

//    @DeleteMapping("/roles/deleteUser")
//    @ResponseBody
//    public String deleteUser(Long id, Model model) {
////        增删改一条数据操作，不需要返回类型，在数据库中增删改一条数据就是返回int的数字类型的行数，没有返回数据类型的意义
//        user1Mapper.deleteUserById1(id);
////        System.out.println("OK");
//        model.addAttribute("users", user1Mapper.user1Select());
//        return "OK";
//    }

}

